#include "draglabel.h"
#include <QMimeData>
#include <QDebug>
#include <QPixmap>
dragLabel::dragLabel(QWidget *parent) : QLabel(parent)
{
    setAcceptDrops(true);
}

void dragLabel::dragEnterEvent(QDragEnterEvent *e)
{
    if(e->mimeData()->hasUrls()){
        e->acceptProposedAction();
    }else e->ignore();
}

void dragLabel::dropEvent(QDropEvent *e)
{
    if(e->mimeData()->hasUrls()){
        QString str=e->mimeData()->urls().at(0).toString();
        str=str.mid(8);//移除前八位 file:///C:/Users/jm/Desktop/Snipaste.png
        this->setPixmap(QPixmap(str));
    }else e->ignore();
}
